package com.dragon.modules.yuegou.service.impl.member;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dragon.modules.yuegou.entity.member.TemplateGradeSetEntity;
import com.dragon.modules.yuegou.mapper.member.TemplateGradeSetMapper;
import com.dragon.modules.yuegou.model.member.TemplateGradeSet;
import com.dragon.modules.yuegou.query.member.TemplateGradeSetQuery;
import com.dragon.modules.yuegou.service.member.TemplateGradeSetService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 会员卡等级条件表 服务实现
 *
 * @author pbuilder generated
 * @date 2021-12-15 11:38:52
 * @version 2.0
 */
@Service("memTemplateGradeSetService")
public class TemplateGradeSetServiceImpl
		extends ServiceImpl<TemplateGradeSetMapper, TemplateGradeSetEntity>
		implements TemplateGradeSetService {

	@Override
	public void saveTemplateGradeSet(String templateSetId, String templateGradeId, List<TemplateGradeSet> gradeSets) {
		if(StringUtils.isNotBlank(templateGradeId)) {
			TemplateGradeSetQuery query = new TemplateGradeSetQuery();
			query.setTemplateSetId(templateSetId);
			query.setTemplateGradeId(templateGradeId);
			remove(query.toQueryWrapper());
		}
		if(CollectionUtils.isNotEmpty(gradeSets)) {
			for(TemplateGradeSet gradeSet : gradeSets) {
				save(gradeSet);
			}
		}
	}
}